package com.xiaouyudeguang.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.DigestUtils;

@Slf4j
@Configuration
public class EncryptUtils {

    private static String encryptKey;

    public EncryptUtils(@Value("${spring.security.clientSign:}") String clientSign) {
        EncryptUtils.encryptKey = DigestUtils.md5DigestAsHex(clientSign.getBytes()).substring(0, 16);
    }

    /**
     * 加密
     *
     * @param content 需要加密的内容
     * @return
     */
    public static String encrypt(String content) {
        return AesUtils.encrypt(content, encryptKey);
    }

    /**
     * AES（256）解密
     *
     * @param content 待解密内容
     * @return 解密之后
     * @throws Exception
     */
    public static String decrypt(String content) {
        return AesUtils.decrypt(content, encryptKey);
    }

}

